<template>
	<view>
		<button type="primary" @click="setStorage">存储数据</button>
		<button type="primary" @click="getStorage">获取数据</button>
	    <button type="primary" @click="removeId">移除id</button>
		<button type="primary" @click="pullDown">下拉刷新</button>
		
		<view>这是列表页</view>
		<view class="box-item" v-for="item in list" :key="item">
			{{item}}
		</view>
	    <custom-tab-bar :direction="direction" :show-icon="showIcon" :selected="selected" @onTabItemTap="onTabItemTap" />
	    <!-- #ifdef H5 -->
		<view>我只希望只在h5页面中看见</view>
		<!-- #endif -->
		<!-- #ifdef MP-WEIXIN -->
		<view>我希望只在微信小程序页面中看见</view>
		<!-- #endif -->
		<button type="primary" @click="chooseImg">上传图片</button>
		<image v-for="item in imgArr" :src="item" :key="imgIndex(item)"></image>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: ['前端','JAVA','UI','测试','大数据'],
				direction: 'horizontal',
				showIcon: true,
				selected: 0,
				imgArr: []
			}
		},
		methods: {
			setStorage() {
				uni.setStorageSync('id', 100);
			},
			getStorage() {
				const res = uni.getStorageSync('id');
				console.log(res);
			},
			removeId () {
				uni.removeStorageSync('id')
			},
			onTabItemTap() {
				// 这里添加点击 tab 的处理逻辑
			},
			onPullDownRefresh () {
				console.log('触发了下拉刷新');
				setTimeout(() => {
					this.list = ['JAVA','UI','前端','测试','大数据'];
					uni.stopPullDownRefresh();
				}, 2000)
			},
			onReachBottom(){
				console.log('页面触底了')
				this.list = [...this.list,...['JAVA','UI','前端','测试','大数据']]
			},
			pullDown(){
				// 通常不需要手动触发下拉刷新
			},
			chooseImg(){
				uni.chooseImage({
					count: 5,
					success: (res) => {
						this.imgArr = res.tempFilePaths
					}
				})
			},
			imgIndex(item) {
				return item; // 这里应该返回一个能够唯一标识每个图片的值
			}
		},
		// 生命周期函数
		onLoad(options) {
			console.log('页面加载了', options);
		},
		onShow() {
			console.log('页面显示了');
		},
		onReady() {
			console.log('页面初次渲染完成了');
		},
		onHide() {
			console.log('页面隐藏了');
		},
	}
</script>

<style>
	.box-item{
		height: 100px;
		line-height: 100px;
		border-bottom: 1px solid #ccc;
	}
	view{
		color: #0000ff;
	}
</style>